home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4686 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.3 KB  |  63 lines

  1. Path: katie.vnet.net!not-for-mail
  2. From: gregg@katie.vnet.net (gregg)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Linking, Libraries and Static memebers
  5. Date: 31 Jan 1996 13:01:32 -0500
  6. Organization: Vnet Internet Access, Charlotte, NC - info@char.vnet.net
  7. Message-ID: <4eoaps$j61@katie.vnet.net>
  8. References: <4elglh$i1l@katie.vnet.net>
  9. NNTP-Posting-Host: katie.vnet.net
  10.  
  11. gregg@katie.vnet.net (gregg) writes:
  12.  
  13. Whoops!  My example code wasn't quite what I had in mind.  Here's the
  14. correction.
  15.  
  16. I've got a class that has some static members, which I've compiled
  17. into a library.  When I try to use those static members in an
  18. application that links in that library, the static members haven't
  19. been initialized!
  20.  
  21. //(The RW prefixed objects are Rouge Wave objects)
  22.  
  23. //file Foo.hpp
  24. class Foo
  25. {
  26. public:
  27.   static RWCString a_string;
  28. }
  29.  
  30. //file Foo.cpp
  31. #include "Foo.hpp"
  32.  
  33. RWCString Foo::a_string = "Initial Value"
  34.  
  35. //Foo.cpp is compiled into a library called Foo.lib.
  36.  
  37. //file App.cpp
  38. #include <iostream.h>
  39. #include "Foo.hpp"
  40.  
  41. class Bar
  42. {
  43.   static RWCString another_string;
  44. }
  45.  
  46. RWCString Bar::another_string = Foo::a_string;
  47.  
  48. main ()
  49. {
  50.   cout << Bar::another_string;
  51. }
  52.  
  53.  
  54. When I run App, I get a null value coming out.  What am I not doing?
  55. I am using MSVC 4.0 under Windows NT.
  56.  
  57. Also, If I run the debugger, on the Bar::another_string assignment
  58. line, Foo::a_string is null.
  59.  
  60. Thanks. Again.
  61.  
  62. -Greg G
  63.